/*
 * Copyright 2010 JooKar (info@jookar.nl)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package nl.jookar.gcodecommithook.handler;

import javax.servlet.http.HttpServletResponse;

/**
 * @author Joost A. Bloemsma
 *
 */
public class HandlerException extends Exception {
	private static final long serialVersionUID = 1L;
	
	public static final int SERVERERROR = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
	public static final int REQUESTERROR = HttpServletResponse.SC_BAD_REQUEST;
	private int errCode = SERVERERROR;
	/**
	 * Constructs a new HandlerException instance
	 */
	public HandlerException() {
		this("unknown internal error");
	}

	/**
	 * Constructs a new HandlerException instance
	 * @param message
	 * @param cause
	 */
	public HandlerException(String message, Throwable cause) {
		this(SERVERERROR, message, cause);
	}

	/**
	 * Constructs a new HandlerException instance
	 * @param cause
	 */
	public HandlerException(Throwable cause) {
		this("unknown internal error", cause);
	}

	/**
	 * Constructs a new HandlerException instance
	 * @param message
	 */
	public HandlerException(String message) {
		this(SERVERERROR, message);
	}

	/**
	 * Constructs a new HandlerException instance
	 * @param errCode
	 * @param message
	 */
	public HandlerException(int errCode, String message) {
		this(errCode, message, null);
	}
	
	/**
	 * Constructs a new HandlerException instance
	 * @param errCode
	 * @param message
	 * @param cause
	 */
	public HandlerException(int errCode, String message, Throwable cause) {
		super(message, cause);
		this.errCode = errCode;
	}

	public int getErrorCode() { return this.errCode; }
}
